package demo3;

import demo2.C;

/**
 * @Author: XXHH
 * @CreateTime: 2024-12-07
 */
public class Test {
    public static void func(Animal animal){
        animal.eat();
    }

    public static void main(String[] args) {
        Animal animal =new Dog("小狗",3);
        if (animal instanceof Cat){
            Cat cat = (Cat) animal;
            cat.miaomiao();
        }else if (animal instanceof Dog){
            Dog dog = (Dog) animal;
            dog.bark();
        }
        /*Cat cat  = (Cat) animal;
        cat.miaomiao();*/
    }
    public static void main4(String[] args) {
        Animal animal =new Dog("小狗",3);
        Dog dog = (Dog)animal;
        dog.bark();
        dog.eat();
    }
    public static void main3(String[] args) {
        Dog dog = new Dog("小狗",2);
        func(dog);
    }
    /*public static void main2(String[] args) {
        Cat cat = new Cat("小猫",3);
        Dog dog = new Dog("小狗",2);
        cat.eat();
        dog.eat();

        Animal animal = new Cat("小黄",4);
        animal.eat();
    }*/
}
